<link rel="stylesheet" href="/js/wechat/assets/css/wx-custom.css">

<div class="box box-info">
<div class="container" id="wechat-menu">

    <!-- 自定义菜单 -->

    <div class="custom-menu-edit-con">
        <input id="_token" type="hidden" value="{{csrf_token()}}">
        <div class="hbox">
            <div class="inner-left">
                <div class="custom-menu-view-con">
                    <div class="custom-menu-view">
                        <div class="custom-menu-view__title">@{{title}}</div>
                        <div class="custom-menu-view__body">
                            <div class="weixin-msg-list"><ul class="msg-con"></ul></div>
                        </div>
                        <div id="menuMain" class="custom-menu-view__footer">
                            <div class="custom-menu-view__footer__left"></div>
                            <div class="custom-menu-view__footer__right" >
                                <div class="custom-menu-view__menu" :class="{subbutton__actived:selectedMenuIndex===i&&selectedMenuLevel()==1}"  v-for="(btn,i) in menu.button" alt="1" style="width: 33.33%;">
                                    <div  @click="selectedMenu(i)" class="text-ellipsis" >@{{ btn.name }}</div>
                                    <ul class="custom-menu-view__menu__sub">

                                        <li class="custom-menu-view__menu__sub__add" v-for="(sub,i2) in btn.sub_button" v-show="selectedMenuIndex===i" :class="{subbutton__actived:selectedSubMenuIndex===i2&&selectedMenuLevel()==2}" @click.stop="selectedSubMenu(i2)">
                                            <div class="text-ellipsis">
                                                @{{ sub.name }}
                                            </div>
                                        </li>
                                        <li class="custom-menu-view__menu__sub__add" v-show="selectedMenuIndex===i">
                                            <div class="text-ellipsis" v-if="btn.sub_button.length<5" @click.stop="addMenu(2)">
                                                <i class="glyphicon glyphicon-plus text-info"></i>
                                            </div>
                                        </li>
                                    </ul>
                                </div>

                                <div class="custom-menu-view__menu" alt="1" style="width: 33.33%;" v-if="menu.button.length<3"   @click="addMenu(1)">
                                    <div class="text-ellipsis">
                                        <i class="glyphicon glyphicon-plus text-info"></i>
                                    </div>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="inner-right">
                <div class="cm-edit-after" v-if="selectedMenuLevel()===1">
                    <div class="cm-edit-right-header b-b"><span id="cm-tit"></span> <a id="delMenu" class="pull-right" href="javascript:;">删除菜单</a></div>
                    <form class="form-horizontal wrapper-md" name="custom_form">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">菜单名称:</label><div class="col-sm-5">
                                <input name="custom_input_title" type="text" class="form-control" v-model="menu.button[selectedMenuIndex].name"  value="" placeholder="" ></div><div class="col-sm-5 help-block">
                                <div >字数不超过5个汉字或16个字符</div>
                                <div class="font_sml" style="display: none;">若无二级菜单，可输入20个汉字或60个字符</div>
                            </div>
                        </div>
                        <div class="form-group" id="radioGroup">
                            <label class="col-sm-2 control-label">菜单内容:</label>
                            <div class="col-sm-10 LebelRadio">
           {{--                     <label class="checkbox-inline"><input type="radio" name="radioBtn" value="sendmsg" checked> 发送消息</label>--}}
                                <label class="checkbox-inline"><input type="radio" name="radioBtn" checked value="link"> 跳转网页</label>
                            </div>
                        </div>
                    </form>

                   {{-- <div class="cm-edit-content-con" id="editMsg">
                        <div class="editTab">
                            <div class="editTab-heading">
                                <ul class="msg-panel__tab">
                                    <li class="msg-tab_item on">
                                        <span class="msg-icon msg-icon-tuwen"></span>
                                        图文消息
                                    </li>
                                </ul>
                            </div>
                            <div class="editTab-body">
                                <div class="msg-panel__context">
                                    <div class="msg-context__item">
                                        <div class="msg-panel__center msg-panel_select"  data-toggle="modal" data-target="#selectModal"><span class="message-plus">+</span><br>从素材库中选择</div>
                                    </div>
                                    <div class="msg-template"></div>
                                </div>
                            </div>
                        </div>
                    </div>--}}
                    <div class="cm-edit-content-con" >
                        <div class="cm-edit-page">
                            <div class="row">
                                <label class="col-sm-6 control-label" style="text-align: left;">粉丝点击该菜单会跳转到以下链接:
                                </label>
                            </div>
                            <div class="row">
                                <label class="col-sm-2 control-label" style="text-align: left;">页面地址:
                                </label>
                                <div class="col-sm-5">
                                    <input type="text" name="url" class="form-control" v-model="menu.button[selectedMenuIndex].url" placeholder="认证号才可手动输入地址">
                                    <span class="help-block">必填,必须是正确的URL格式</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div >
                <div class="cm-edit-after" v-if="selectedMenuLevel()===2">
                    <div class="cm-edit-right-header b-b"><span id="cm-tit"></span> <a id="delMenu" class="pull-right" href="javascript:;">删除菜单</a></div>
                    <form class="form-horizontal wrapper-md" name="custom_form">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">菜单名称:</label><div class="col-sm-5">
                                <input name="custom_input_title" type="text" class="form-control" v-model="menu.button[selectedMenuIndex].sub_button[selectedSubMenuIndex].name"  value="" placeholder="" ></div><div class="col-sm-5 help-block">
                                <div >字数不超过5个汉字或16个字符</div>
                                <div class="font_sml" style="display: none;">若无二级菜单，可输入20个汉字或60个字符</div>
                            </div>
                        </div>
                        <div class="form-group" id="radioGroup">
                            <label class="col-sm-2 control-label">菜单内容:</label>
                            <div class="col-sm-10 LebelRadio">
           {{--                     <label class="checkbox-inline"><input type="radio" name="radioBtn" value="sendmsg" checked> 发送消息</label>--}}
                                <label class="checkbox-inline"><input type="radio" name="radioBtn" checked value="link"> 跳转网页</label>
                            </div>
                        </div>
                    </form>

                   {{-- <div class="cm-edit-content-con" id="editMsg">
                        <div class="editTab">
                            <div class="editTab-heading">
                                <ul class="msg-panel__tab">
                                    <li class="msg-tab_item on">
                                        <span class="msg-icon msg-icon-tuwen"></span>
                                        图文消息
                                    </li>
                                </ul>
                            </div>
                            <div class="editTab-body">
                                <div class="msg-panel__context">
                                    <div class="msg-context__item">
                                        <div class="msg-panel__center msg-panel_select"  data-toggle="modal" data-target="#selectModal"><span class="message-plus">+</span><br>从素材库中选择</div>
                                    </div>
                                    <div class="msg-template"></div>
                                </div>
                            </div>
                        </div>
                    </div>--}}
                    <div class="cm-edit-content-con" >
                        <div class="cm-edit-page">
                            <div class="row">
                                <label class="col-sm-6 control-label" style="text-align: left;">粉丝点击该菜单会跳转到以下链接:
                                </label>
                            </div>
                            <div class="row">
                                <label class="col-sm-2 control-label" style="text-align: left;">页面地址:
                                </label>
                                <div class="col-sm-5">
                                    <input type="text" name="url" class="form-control" placeholder="认证号才可手动输入地址" v-model="menu.button[selectedMenuIndex].sub_button[selectedSubMenuIndex].url">
                                    <span class="help-block">必填,必须是正确的URL格式</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div >
                <div class="cm-edit-before" v-if="!menu.button[selectedMenuIndex]"><h5>点击左侧菜单进行操作</h5></div>
            </div>
        </div>
    </div>
    <div class="cm-edit-footer">
        <button id="sortBtn" type="button" class="btn btn-default">菜单排序</button>
        <button id="sortBtnc" type="button" class="btn btn-default">完成排序</button>
        <button id="saveBtns" type="button" class="btn btn-info1">保存</button>
    </div>
</div>
</div>
<!-- 自定义菜单排序 -->
<script src="/js/wechat/assets/js/Sortable.js"></script>

<div id="selectModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span>×</span></button>
                <h4 class="modal-title">
                    选择图片
                </h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div id="col_1" class="col-xs-4">
                        <div class="panel panel-default">
                            <div class="panel-heading msg-date">
                                08月12日
                            </div>
                            <div class="panel-body">
                                <h5 class="msg-title">微信缴费使用指南1</h5>
                                <div class="msg-img"><img src="/js/wechat/assets/images/20170831595cf16beb634972a65adb6b14abca9b.jpg" alt=""></div>
                                <p class="msg-text">微信缴费使用指南</p>
                            </div>
                            <div class="mask-bg"><div class="mask-icon"><i class="icon-ok"></i></div></div>
                        </div>
                    </div>
                    <div id="col_2" class="col-xs-4">
                        <div class="panel panel-default">
                            <div class="panel-heading msg-date">
                                08月31日
                            </div>
                            <div class="panel-body">
                                <h5 class="msg-title">微信缴费使用指南2</h5>
                                <div class="msg-img"><img src="/js/wechat/assets/images/1.png" alt=""></div>
                                <p class="msg-text">微信缴费使用指南</p>
                            </div>
                            <div class="mask-bg"><div class="mask-icon"><i class="icon-ok"></i></div></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info ensure">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<div id="reminderModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span>×</span></button>
                <h4 class="modal-title">
                    温馨提示
                </h4>
            </div>
            <div class="modal-body">
                <h5>添加子菜单后，一级菜单的内容将被清除。确定添加子菜单？</h5>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info reminder">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>

</div>

<div id="abnormalModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span>×</span></button>
                <h4 class="modal-title">
                    温馨提示
                </h4>
            </div>
            <div class="modal-body">
                <h5>数据异常</h5>
            </div>
            <div class="modal-footer">
                <!-- <button type="button" class="btn btn-info reminder">确定</button> -->
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>

</body>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>

<script>
    var app=new Vue(
        {
            el:'#wechat-menu',

            //菜单对象
            data:{
                title: '{{config('app.name')}}',
                menu: {
                    "button": [
                        {
                            "name": "主菜单1",
                            "sub_button": []
                        },
                       ]
            },
            input_name:'',
            selectedMenuIndex:'',//当前选中菜单索引
            selectedSubMenuIndex:'',//当前选中子菜单索引
        },
            watch:{
                input_name:function(val, oldVal){
                    if(this.selectedMenuLevel()==2){
                        this.menu.button[this.selectedMenuIndex].sub_button[this.selectedSubMenuIndex].name=this.input_name;
                    }else{
                        this.menu.button[this.selectedMenuIndex].name=this.input_name;
                    }
                }
            },

            methods:{
                //选中主菜单
                selectedMenu:function (i) {
                    this.selectedSubMenuIndex = ''
                    this.selectedMenuIndex = i
                },
                //选中子菜单
                selectedSubMenu:function (i) {
                    this.selectedSubMenuIndex = i
                },
                //选中菜单级别
                selectedMenuLevel: function () {
                    if (this.selectedMenuIndex !== '' && this.selectedSubMenuIndex === '') {
                        //主菜单
                        return 1;
                    } else if (this.selectedMenuIndex !== '' && this.selectedSubMenuIndex !== '') {
                        //子菜单
                        return 2;
                    } else {
                        //未选中任何菜单
                        return 0;
                    }
                },
                //添加菜单
                //参数level为菜单级别，1为主菜单、2为子菜单
                addMenu:function (level) {
                    if (level == 1 && this.menu.button.length < 3) {
                        this.menu.button.push({"name": "菜单名称",
                            "type":'view',
                            'url':'',
                        })
                        this.selectedMenuIndex = this.menu.button.length - 1
                        this.selectedSubMenuIndex = ''
                    }
                    if (level == 2 && this.menu.button[this.selectedMenuIndex].sub_button.length < 5) {
                        this.menu.button[this.selectedMenuIndex].push({"sub_button":[]});
                        delete this.menu.button[this.selectedMenuIndex].type;
                        delete this.menu.button[this.selectedMenuIndex].url;
                        this.menu.button[this.selectedMenuIndex].sub_button.push({
                            "name": "子菜单名称",'type':"view","url":""
                        })
                        this.selectedSubMenuIndex = this.menu.button[this.selectedMenuIndex].sub_button.length - 1
                    }
                },
                delMenu:function(){
                    //删除主菜单
                    if(this.selectedMenuLevel()==1&&confirm('删除后菜单下设置的子菜单也将被删除')){
                        if(this.selectedMenuIndex===0){
                            this.menu.button.splice(this.selectedMenuIndex, 1);
                            this.selectedMenuIndex = 0;
                        }else{
                            this.menu.button.splice(this.selectedMenuIndex, 1);
                            this.selectedMenuIndex -=1;
                        }
                        if(this.menu.button.length==0){
                            this.selectedMenuIndex = ''
                        }
                        //删除子菜单
                    }else if(this.selectedMenuLevel()==2){
                        if(this.selectedSubMenuIndex===0){
                            this.menu.button[this.selectedMenuIndex].sub_button.splice(this.selectedSubMenuIndex, 1);
                            this.selectedSubMenuIndex = 0;
                        }else{
                            this.menu.button[this.selectedMenuIndex].sub_button.splice(this.selectedSubMenuIndex, 1);
                            this.selectedSubMenuIndex -= 1;
                        }
                        if(this.menu.button[this.selectedMenuIndex].sub_button.length==0){
                            this.selectedSubMenuIndex = ''
                        }
                    }
                },
            }

    });
</script>
</html>
